﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using ExtAspNet;
using System.Data;

public partial class Module_StaffManger_StaffScore : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PreLoadGvList();
        }

    }

    private void PreLoadGvList()
    {
        if (Request.QueryString["StaffID"] != null)
        {
            LoadGvList(Request.QueryString["StaffID"].ToString());
        }
        else
        {
            LoadGvList(StaffID.ToString());
        }
    }

    private void LoadGvList(string StaffID)
    {
        LoadIntentCust(StaffID);
        LoadProtectCust(StaffID);
        LoadDeleteCust(StaffID);
    }

    /// <summary>
    /// 意向客户
    /// </summary>
    /// <param name="StaffID"></param>
    private void LoadIntentCust(string StaffID)
    {
        Ylh.BLL.CustBLL bllc = new Ylh.BLL.CustBLL(DbConnectionStr);
       Grid2.DataSource= bllc.GetCustListByCondition(StaffID, false, false);
       Grid2.DataBind();
    }

    /// <summary>
    /// 保护客户
    /// </summary>
    /// <param name="StaffID"></param>
    private void LoadProtectCust(string StaffID)
    {
        Ylh.BLL.CustBLL bllc = new Ylh.BLL.CustBLL(DbConnectionStr);
       Grid1.DataSource= bllc.GetCustListByCondition(StaffID, true, false);
       Grid1.DataBind();
    }


    /// <summary>
    /// 已经删除客户
    /// </summary>
    /// <param name="StaffID"></param>
    private void LoadDeleteCust(string StaffID)
    {
        Ylh.BLL.CustBLL bllc = new Ylh.BLL.CustBLL(DbConnectionStr);
       Grid3.DataSource= bllc.GetCustListByCondition(StaffID, null, false);
       Grid3.DataBind();
    }


    //protected void Grid3_RowClick(object sender, ExtAspNet.GridRowClickEventArgs e)
    //{
    //    string str = Grid3.DataKeys[e.RowIndex][0].ToString();

    //    if (Request.QueryString["StaffID"] != null)
    //    {
    //        PageContext.RegisterStartupScript(Window1.GetShowReference("../CustManger/CustInfo.aspx?StaffID=" + Request.QueryString["StaffID"].ToString() + "&CustID=" + str, "客户相关信息"));
    //    }
    //    else
    //    {
    //        PageContext.RegisterStartupScript(Window1.GetShowReference("../CustManger/CustInfo.aspx?CustID=" + str, "客户相关信息"));
    //    }
    //}






    protected void Window2_Close(object sender, WindowCloseEventArgs e)
    {
        Ylh.BLL.CustBLL bll = new Ylh.BLL.CustBLL(DbConnectionStr);

        bll.UpdateBussinStaff(CustID.Text, staffID.Text);

        PreLoadGvList();
    }



    protected void Grid2_RowDataBound(object sender, GridRowEventArgs e)
    {
        System.Web.UI.WebControls.LinkButton lbf = (System.Web.UI.WebControls.LinkButton)Grid2.Rows[e.RowIndex].FindControl("LinkButton1");
        string str = Grid2.DataKeys[e.RowIndex][0].ToString();
        lbf.OnClientClick = Window2.GetSaveStateReference(staffID.ClientID, tel.ClientID, Name.ClientID, CustID.ClientID) + Window2.GetShowReference("StaffTree.aspx?CustID=" + str, "选择员工");
        System.Web.UI.WebControls.LinkButton lbf2 = (System.Web.UI.WebControls.LinkButton)Grid2.Rows[e.RowIndex].FindControl("LinkButton2");

        if (Request.QueryString["StaffID"] != null)
        {
            lbf2.OnClientClick=Window1.GetShowReference("../CustManger/CustInfo.aspx?StaffID=" + Request.QueryString["StaffID"].ToString() + "&CustID=" + str, "客户相关信息");
        }
        else
        {
            lbf2.OnClientClick=Window1.GetShowReference("../CustManger/CustInfo.aspx?CustID=" + str, "客户相关信息");
        }
    }

    protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
    {
        System.Web.UI.WebControls.LinkButton lbf = (System.Web.UI.WebControls.LinkButton)Grid1.Rows[e.RowIndex].FindControl("LinkButton4");
        string str = Grid1.DataKeys[e.RowIndex][0].ToString();
        lbf.OnClientClick = Window2.GetSaveStateReference(staffID.ClientID, tel.ClientID, Name.ClientID, CustID.ClientID) + Window2.GetShowReference("StaffTree.aspx?CustID=" + str, "选择员工");
        System.Web.UI.WebControls.LinkButton lbf2 = (System.Web.UI.WebControls.LinkButton)Grid1.Rows[e.RowIndex].FindControl("LinkButton3");

        if (Request.QueryString["StaffID"] != null)
        {
            lbf2.OnClientClick = Window1.GetShowReference("../CustManger/CustInfo.aspx?StaffID=" + Request.QueryString["StaffID"].ToString() + "&CustID=" + str, "客户相关信息");
        }
        else
        {
            lbf2.OnClientClick = Window1.GetShowReference("../CustManger/CustInfo.aspx?CustID=" + str, "客户相关信息");
        }
    }

    protected void Grid3_RowDataBound(object sender, GridRowEventArgs e)
    {
        System.Web.UI.WebControls.LinkButton lbf = (System.Web.UI.WebControls.LinkButton)Grid3.Rows[e.RowIndex].FindControl("LinkButton6");
        string str = Grid3.DataKeys[e.RowIndex][0].ToString();
        lbf.OnClientClick = Window2.GetSaveStateReference(staffID.ClientID,tel.ClientID,  Name.ClientID, CustID.ClientID) + Window2.GetShowReference("StaffTree.aspx?CustID=" + str,"选择员工");
        System.Web.UI.WebControls.LinkButton lbf2 = (System.Web.UI.WebControls.LinkButton)Grid3.Rows[e.RowIndex].FindControl("LinkButton5");

        if (Request.QueryString["StaffID"] != null)
        {
            lbf2.OnClientClick = Window1.GetShowReference("../CustManger/CustInfo.aspx?StaffID=" + Request.QueryString["StaffID"].ToString() + "&CustID=" + str, "客户相关信息");
        }
        else
        {
            lbf2.OnClientClick = Window1.GetShowReference("../CustManger/CustInfo.aspx?CustID=" + str, "客户相关信息");
        }
    }



    protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
    {
        Grid1.PageIndex = e.NewPageIndex;
    }
    protected void Grid2_PageIndexChange(object sender, GridPageEventArgs e)
    {
        Grid2.PageIndex = e.NewPageIndex;
    }
    protected void Grid3_PageIndexChange(object sender, GridPageEventArgs e)
    {
        Grid3.PageIndex = e.NewPageIndex;
    }
}